<?php
/*
$info = htmlspecialchars(@$_GET['info']);
$path = htmlspecialchars(@$_GET['path']);
$information = "GET\ninfo=$info\npath=$path\n\n";
*/
$feedback = date(DATE_ATOM) . "\n";
$information = "timestamp " .time() . " ip ".getRealIpAddr(). " ". gethostbyaddr(getRealIpAddr()). " ";

if (!empty($_POST))
{
  $feedback .= "POST\n";
  $c = 1;
  foreach ($_POST as $k => $v)
  {
    $feedback .= "[$c] $k = $v\n";
	$k = str_replace("\n","|",$k);
	$v = str_replace("\n","|",$v);
    $information .= "$k $v ";
    $c++;
  }
  $information .="\n";
}

$logFileName = 'PHP_log_requests.log';
$fh = fopen($logFileName, 'a') or die("Cannot open for write " . $logFileName);
fwrite($fh, $information);
fclose($fh);

// Send back what have been received
echo($feedback);


function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
?>